package com.fkcai.hansoul.model.vo.post;

import com.fkcai.hansoul.model.entity.Post;
import com.fkcai.hansoul.model.entity.User;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 获取帖子响应数据 VO 类
 */
@Data
public class GetPostVo {
	private Integer postId;
	private String title;
	private Integer categoryId;    // 类别 id
	private String postStatus;      // 帖子状态
	private Integer likeCount;
	private LocalDateTime createTime;
	private List<String> imageUrls; // 图片地址列表
	
	private UserInfo user;
	
	/**
	 * 嵌套用户信息
	 */
	@Data
	public static class UserInfo {
		private Integer userId;
		private String username;     // 用户名
		private String avatarUrl;     // 头像URL
		
		// 从用户实体类中获取用户信息
		public static UserInfo fromUser (User user) {
			UserInfo userInfo = new UserInfo();
			
			userInfo.setUserId(user.getUserId());
			userInfo.setUsername(user.getUsername());
			userInfo.setAvatarUrl(user.getAvatarUrl());
			
			return userInfo;
		}
	}
	
	// 从帖子实体类中获取帖子信息
	public static GetPostVo fromPost (Post post, User user,  List<String> imageUrls) {
		GetPostVo getPostVo = new GetPostVo();
		
		getPostVo.setPostId(post.getPostId());
		getPostVo.setTitle(post.getTitle());
		getPostVo.setCategoryId(post.getCategoryId());
		getPostVo.setPostStatus(post.getPostStatus());
		getPostVo.setLikeCount(post.getLikeCount());
		getPostVo.setCreateTime(post.getCreateTime());
		
		getPostVo.setImageUrls(imageUrls);
		
		if (user != null) {
			getPostVo.setUser(UserInfo.fromUser(user));
		}
		
		return getPostVo;
	}
	
}
